Mike: Every developer dreams
of a world where the developer
doesn’t have to set up and manage infrastructure, especially if all that’s needed
is a small bit of logic to do some quick processing
on a piece of data. Cloud Functions
make it possible to run a completely
serverless environment, where logic can be executed
on demand and in response to events. Cloud Functions can act as a glue
between disparate applications. With Cloud Functions, you can build a serverless
microservices architecture that’s highly scalable. You can simply focus
on the code and not worry about setting up
servers to run that code. In this module, Using Cloud Functions
for Event-Driven Processing, you’ll learn
about Cloud Functions triggers, you’ll learn
how to execute Cloud Functions in response
to asynchronous events and synchronous
HTTP invocations. You’ll develop
and deploy Cloud Functions to perform
event-driven processing, and you’ll learn
how to handle logging, error reporting,
and monitoring for Cloud Functions. Google Cloud Services
emit events, such as when files are uploaded
to a Google Cloud Storage bucket, or messages
are published to a Pub Sub topic. External services can invoke
functions in response to events in their systems, such as when a commit
is made to a GitHub repository, Cloud Functions are triggered
in response to these events. Cloud
Functions can invoke other APIs or write data
back to the Cloud. With Cloud Functions,
you can develop an application that is event-driven,
serverless and highly scalable. Each function
is lightweight microservice that enables you to integrate
application components and data sources. Cloud Functions are ideal
for microservices that require
a small piece of code to quickly process data
related to an event. Cloud Functions are priced according to how long
your function runs, the number of times
it is invoked, and the resources that
you provision for the function. Consider an application that
allows users to upload images that contain text to a bucket
in Google Cloud Storage.
The OCR Cloud Function is triggered
when a new image is uploaded
to the images bucket. This function uses
the Vision API to extract text from images, and then queues up the text
in Pub Sub for translation. The translator Cloud Function
triggered by the Pub Sub topic
invokes the Cloud Translation API to translate the text. It queues up the translated
text in the file writer topic in Pub Sub.
The file writer Cloud Function writes the translated
text for each image as separate files in Cloud
Storage. In this example, all components
of the application use fully managed services and APIs, such as Cloud
Storage, Pub Sub, Cloud Functions, the Vision API,
and the Cloud Translation API. These services scale
automatically depending on the volume
of incoming data in required compute resources. This scalability
and reliability enables you to focus
on your application code. Cloud Functions can be used
in a variety of use cases that require
lightweight microservices or event-driven processing. Cloud Functions
can serve as web hooks. For example,
you can set up a web hook that is invoked automatically
after each commit to a Git repository. External and internal clients
can make direct HTTP calls to invoke microservices that are deployed
as Cloud Functions. You can use Cloud Functions
for lightweight Extract Transform load,
or ETL operations. For example, when a file
is uploaded to Cloud Storage, a Cloud Function
can be triggered to transform and upload the contents
to a database. You can also use
Cloud Functions to process IoT streaming data,
or other application messages that are published
to a Pub Sub topic. Cloud Functions
is a scalable Pay As You Go functions as a service, which enables you
to run your code with zero server management. Cloud
Functions is highly scalable, automatically scaling up
and down in response to events. You are only billed for
your function’s execution time metered to the nearest
100 milliseconds. You pay nothing
when your function is idle. Cloud functions can be
written in node.js, Python, Go and Java, and are executed
in language specific runtimes. Cloud Functions
can be triggered asynchronously in response
to events such as those in Cloud Storage,
Pub Sub or Firebase. Asynchronously
triggered functions are called
background functions. Cloud Functions can also be
invoked synchronously by direct HTTP request responses. Functions invoked
in this manner are called HTTP functions.
Remember, Cloud Functions have a default
timeout value of 60 seconds. Ensure that the function
will complete execution before timing out. For HTTP functions, it is important to keep
the execution time to a minimum to avoid
a negative user experience.